package com.example.moonshine.baidumap.Util;

import android.util.Log;

import com.example.moonshine.baidumap.Modle.MsgStatus;
import com.google.gson.Gson;

import java.io.IOException;

import okhttp3.FormBody;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;

import static android.content.ContentValues.TAG;

public class SpostHttpMap {
    public String Postmap(String url,String gpsPoint,String token,String name) {
        //okhttp Post请求传输Json数据
        OkHttpClient client = new OkHttpClient();
        String postStatus = null;
        Gson gson = new Gson();
        FormBody body = new FormBody.Builder()
                .add("gpsPoint",gpsPoint)
                .add("username",name)
                .build();
        Request request = new Request.Builder()
                .addHeader("accessToken",token)
                .url(url)
                .post(body)
                .build();
        try {
            Response response = client.newCall(request).execute();
            String result = response.body().string();
            MsgStatus msgData = gson.fromJson(result,MsgStatus.class);
            postStatus =msgData.getMsg();
            Log.i(TAG,"gps返回值"+postStatus);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return postStatus;
    }

    public String Postmapfinish(String url,String token,String manholeId) {
        //okhttp Post请求传输Json数据
        OkHttpClient client = new OkHttpClient();
        String postStatus = null;
        Gson gson = new Gson();
        FormBody body = new FormBody.Builder()
                 .add("manholeId",manholeId)
                .build();
        Request request = new Request.Builder()
                .addHeader("accessToken",token)
                .url(url)
                .post(body)
                .build();
        try {
            Response response = client.newCall(request).execute();
            String result = response.body().string();
            Log.i(TAG,"完成任务返回值"+result);
            MsgStatus msgData = gson.fromJson(result,MsgStatus.class);
            postStatus = msgData.getMsg();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return postStatus;
    }
}
